﻿using System.Configuration;
using Framework.Core.Io;
using Xunit;

namespace Framework.Tests.Core
{
    public interface IEnvironment
    {
        string Environment { get; }
    }

    public class TestSettings : ConfigurationSection, IEnvironment
    {
        [ConfigurationProperty("env")]
        public string Environment
        {
            get { return (string)this["env"]; }
        }
    }

    public class TestSettings2 : TestSettings
    {
    }

    public class ConfigurationManagerAdapterTest
    {
        private readonly IConfigurationManagerAdapter target = new ConfigurationManagerAdapter();

        public static void AssertTest_Naming_Convention(string expected, string arg)
        {
            var actual = ConfigurationManagerAdapter.GetSectionName(arg);
            Assert.Equal(expected, actual);
        }

        [Fact]
        public void Test_Naming_Convention()
        {
            AssertTest_Naming_Convention("pouet", "Pouet");
            AssertTest_Naming_Convention("pouetPouet", "PouetPouet");
            //No need No code (for words camel convention)
            AssertTest_Naming_Convention("hello World", "Hello World");
        }

        [Fact]
        public void Test_GetSection_Succeed()
        {
            Assert.Equal("Dev", target.GetSection<IEnvironment, TestSettings>().Environment);
        }

        [Fact]
        public void Test_GetSection_EmptyConfig_Succeed()
        {
            Assert.Null(target.GetSection<IEnvironment, TestSettings2>());
        }

        [Fact]
        public void Test_GetConnectionString_Succeed()
        {
            Assert.Equal("pouet", target.GetConnectionString("SQL"));
        }
    }
}